<template>
  <el-container>
    <el-header>
      <div class="left-panel">
        <!-- <el-button v-if="$AUTH('system:sysParameter:add')" type="primary" icon="el-icon-plus" @click="add"></el-button> -->
      </div>
      <div class="right-panel">
        <div class="right-panel-search">
		  <selectSystem :parentLoadingFunction="parentLoadingFunction" :parentGetData="parentGetData" :styleData="selStyleIn" :placeholderData="'请您先选择系统！'"/>
           <el-input v-model="search.parameterName" placeholder="名称" clearable style="width:200px;"></el-input>
           <el-select v-model="search.dataType" placeholder="类型" clearable style="width:100px;">
				<el-option label="单选框" value="1" /><el-option label="复选框" value="2" />
          		<el-option label="下拉框" value="5" /><el-option label="输入框" value="3" /><el-option label="textarea文本域" value="4" />
           </el-select>
           <el-input v-model="search.numb" placeholder="编码" clearable style="width:150px;"></el-input>
          <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
        </div>
      </div>
    </el-header>
    <el-main class="nopadding" v-loading="showloading">
      <scTable ref="table" :apiObj="apiObj" :loadNow="false" row-key="sysParameterId" :initMsg="'请您选选择系统!'" @selection-change="selectionChange" stripe>
        <el-table-column type="selection" width="50"></el-table-column>
        <el-table-column label="ID" prop="sysParameterId" width="70"></el-table-column>
        <el-table-column label="系统" prop="systemLevelId" width="150"></el-table-column>
        <el-table-column label="名称" prop="parameterName" width="150"></el-table-column>
        <el-table-column label="内容" prop="dataValue" width="500"></el-table-column>
        <el-table-column label="类型" width="100">
        	<template #default="scope">
        		<span v-if="scope.row.dataType==1">单选框</span><span v-if="scope.row.dataType==2">复选框</span><span v-if="scope.row.dataType==5">下拉框</span>
        		<span v-if="scope.row.dataType==3">输入框</span><span v-if="scope.row.dataType==4">textarea文本域</span>
        	</template>
        </el-table-column>
        <el-table-column label="备注" prop="msg" width="150"></el-table-column>
        <el-table-column label="编码" prop="numb" width="100"></el-table-column>
        <el-table-column label="排序" prop="seq" width="80"></el-table-column>
        <el-table-column label="操作" fixed="right" align="right">
          <template #default="scope">
            <el-button v-if="$AUTH('system:sysParameter:edit')" type="text" size="small" @click="table_edit(scope.row, scope.$index)">编辑</el-button>
            <!-- <el-divider direction="vertical"></el-divider>
            <el-button v-if="$AUTH('system:sysParameter:del')" type="text" size="small" @click="table_del(scope.row, scope.$index)">删除</el-button> -->
          </template>
        </el-table-column>
      </scTable>
    </el-main>
  </el-container>
  <sysParameterEdit-dialog v-if="dialog.sysParameterEdit" ref="sysParameterEditDialog" @success="handleSaveSuccess" @closed="dialog.sysParameterEdit=false"></sysParameterEdit-dialog>
</template>
<script>
  import systemAPI from '@/api/system/sysParameter';
  import sysParameterEditDialog from './sysParameterEdit';//1--导入
  import selectSystem from '@/components/glSelectCO/selectSystem';
  export default {
    name: 'sysParameter',
    components: {
        sysParameterEditDialog,selectSystem
    },
    data() {
      return {
        dialog: {
          sysParameterEdit: false
        },
        apiObj: systemAPI.sysParameter.list,
		loadNow: false,
        selection: [],
        search: {
          keyword: null,
          createTime: null,
		  dataType: null,
		  systemLevelId: null,
		  sysBranchOfficeId: null,
		  parameterName: null,
		  numb: null,
        },
		showloading: false,
		systemTypeName: null,
		selStyleIn: "border:1px solid #ffaaff;width:200px;",
      }
    },
    methods: {
      //添加
      add(){
		  if(!this.search.systemLevelId || this.search.systemLevelId==""){
		  	this.selStyleIn="border:2px solid #f90505;";
		  	this.$message.warning("请您先选择企业！")
		  	return false;
		  }
			this.dialog.sysParameterEdit = true;
			this.$nextTick(() => {
				let newData = {"systemLevelId":this.search.systemLevelId, "systemTypeName":this.systemTypeName};
				this.$refs.sysParameterEditDialog.open('add').setData(newData);
			});
      },
      //编辑
      table_edit(row){
        this.dialog.sysParameterEdit = true
        this.$nextTick(() => {
			row.systemTypeName=this.systemTypeName;//json添加属性
			this.$refs.sysParameterEditDialog.open('edit').setData(row);
        })
      },
      //删除
      async table_del(row){
        var confirm = await this.$confirm('确定删除选中的项吗？', '提示', {
          confirmButtonText: 'ok',
          type: 'warning'
        }).catch(() => {})
        if(confirm !== 'confirm'){
          return false;
        }
        var res = await systemAPI.sysParameter.delete.delete(row.sysParameterId);
        if(res.code === 2000){
          this.$refs.table.refresh();
          this.$message.success("删除成功");
        }else{
          this.$alert(res.message, "提示", {type: 'error'});
        }
      },
      //表格选择后回调事件
      selectionChange(selection){
        this.selection = selection;
      },
      //搜索
      upsearch(){
        this.$refs.table.upData(this.search);
      },
      //本地更新数据
      handleSaveSuccess(){
        this.$refs.table.refresh();
      },
      handlePermissionSuccess(){
        this.$refs.table.refresh();
      },
      handleDataSuccess(){
        this.$refs.table.refresh();
      },
      formatDate(row,column) {// 获取单元格数据
        let data = row[column.property];
        if(data == null) {
          return null;
        }
        let dt = new Date(data);
        return dt.getFullYear() + '-' + (dt.getMonth() + 1) + '-' + dt.getDate() + ' ' + dt.getHours() + ':' + dt.getMinutes() + ':' + dt.getSeconds();
      },
	  parentLoadingFunction(loadingBz){//选择 公司  分公司 回调函数 ---- 加载提醒
	  	this.showloading = loadingBz;
	  },
	  parentGetData(item){//选择 公司  分公司 回调函数 ---- 重新获取数据
	  	this.search.systemLevelId = item.systemLevelId;
		this.systemTypeName = item.typeName;
		this.upsearch();
	  },
    }
  }
</script>
<style>
</style>
